/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aic.rest;

import aic.beans.Customer;
import aic.lists.CustomerList;
import aic.misc.DebugPrint;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;



@Path("/CustomerManagementService/")
@Produces("application/xml")
public class CustomerManagementService {

    public CustomerManagementService() {
    }


    @GET
    @Path("/retrieveCustomer/{id}")
    public Customer retrieveCustomer(@PathParam("id") String id) {
        return CustomerList.getCustomer(id);
    }

    @PUT
    @Path("/updateCustomer/")
    public Response updateCustomer(Customer customer) {
        if(customer == null)
            return Response.status(Response.Status.FORBIDDEN).build();
        try{
            DebugPrint.println("updating Customer in RESTService..");
            CustomerList.updateCustomer(customer);
            CustomerList.printList();
            DebugPrint.println("updating Customer in RESTService done!");

            return Response.status(Response.Status.OK).build();
        }catch(Exception e){
            return Response.status(Response.Status.CONFLICT).build();
        }
    }

    @POST
    @Path("/createCustomer/")
    public Response createCustomer(Customer customer) {
        if(customer == null)
            return Response.status(Response.Status.FORBIDDEN).build();
        try{
            DebugPrint.println("creating and adding new Customer in RESTService..");
            
            CustomerList.add(customer);
            CustomerList.printList();
            DebugPrint.println("..creating and adding new Customer in RESTService done!");

            return Response.status(Response.Status.OK).build();
        }catch(Exception e){
            return Response.status(Response.Status.CONFLICT).build();
        }
    }

    @DELETE
    @Path("/deleteCustomer/{id}")
    public Response deleteCustomer(@PathParam("id") String id) {
        if(CustomerList.deleteCustomer(id))
            return Response.status(Response.Status.OK).build();
        else
            return Response.status(Response.Status.FORBIDDEN).build();
    }
}

